package com.xr.system.teacher.controller;

import com.xr.common.annotation.SystemLog;
import com.xr.common.enums.LogType;
import com.xr.feignApi.student.StudentFeignApi;
import com.xr.system.model.student.dto.StudentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.ApiOperation;
import com.xr.common.axios.AxiosResult;
import com.xr.common.axios.AxiosEnum;
import com.xr.system.model.teacher.dto.TeacherDto;
import com.xr.system.teacher.service.ITeacherService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Teacher信息表
 *
 * @author fzh
 * @email e_341877120_mail@163.com
 * @date 2022-09-30 10:21:20
 */
@RestController
@RequestMapping("/api/v1/teacher")
public class TeacherController {

	@Autowired
	private ITeacherService iTeacherService;

	@Autowired
	private StudentFeignApi studentFeignApi;

	/**
	 * 远程调用查询学生信息
	 * @param studentDto
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.SELECT, description = "远程调用查询Student信息")
	@ApiOperation(tags = "查询", value = "远程调用查询学生信息")
	@GetMapping("/selectStudentList")
	public AxiosResult selectStudentList(StudentDto studentDto) {
		return studentFeignApi.selectList(studentDto);
	}

	/**
	 * 根据条件查询列表
	 * @param teacherDto
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "查询Teacher信息")
	@GetMapping("/selectList")
	public AxiosResult selectList(TeacherDto teacherDto) {
		return iTeacherService.selectList(teacherDto);
	}

	/**
	 * 根据条件分页查询
	 * @param currentPage
	 * @param pageSize
	 * @param teacherDto
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "分页查询Teacher信息")
	@GetMapping("/selectPage/{currentPage}/{pageSize}")
	public AxiosResult selectPage(@PathVariable int currentPage, @PathVariable int pageSize, TeacherDto teacherDto) {
		return iTeacherService.selectPage(currentPage, pageSize, teacherDto);
	}

	/**
	 * 根据id查询单个
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "根据id查询Teacher信息")
	@GetMapping("/selectOneById/{id}")
	public AxiosResult selectOneById(@PathVariable Long id) {
		return iTeacherService.selectOneById(id);
	}

	/**
	 * 新增
	 * @param teacherDto
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.INSERT, description = "新增Teacher信息")
	@ApiOperation(tags = "新增", value = "新增Teacher信息")
	@PostMapping("/insert")
	public AxiosResult insert(@RequestBody TeacherDto teacherDto) {
		return iTeacherService.insert(teacherDto);
	}

	/**
	 * 更新
	 * @param teacherDto
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.UPDATE, description = "更新Teacher信息")
	@ApiOperation(tags = "更新", value = "更新Teacher信息")
	@PutMapping("/update")
	public AxiosResult update(@RequestBody TeacherDto teacherDto) {
		return iTeacherService.update(teacherDto);
	}

	/**
	 * 根据id删除单个
	 * @param id
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.DELETE, description = "删除Teacher信息")
	@ApiOperation(tags = "删除", value = "删除Teacher信息")
	@DeleteMapping("/delete/{id}")
	public AxiosResult delete(@PathVariable Long id) {
		return iTeacherService.delete(id);
	}

	/**
	 * 根据id集合批量删除
	 * @param idList
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.DELETE, description = "批量删除Teacher信息")
	@ApiOperation(tags = "删除", value = "批量删除Teacher信息")
	@PostMapping("/deleteBatch")
	public AxiosResult deleteBatch(@RequestBody List<Long> idList) {
		return iTeacherService.deleteBatch(idList);
	}

	/**
	 * 导入文件
	 * @param file
	 * @return
	 */
	@SystemLog(module = "Teacher模块", type = LogType.IMPORT, description = "导入Teacher信息")
	@ApiOperation(tags = "导入", value = "导入Teacher信息")
	@PostMapping("/importFile")
	public AxiosResult importFile(@RequestBody MultipartFile file) {
		return iTeacherService.importFile(file);
	}

	/**
	 * 导出文件
	 * @param response
	 */
	@SystemLog(module = "Teacher模块", type = LogType.EXPORT, description = "导出Teacher信息")
	@ApiOperation(tags = "导出", value = "导出Teacher信息")
	@GetMapping("/exportFile")
	public AxiosResult exportFile(HttpServletResponse response) {
		iTeacherService.exportFile(response);
		return AxiosResult.success(AxiosEnum.EXPORT_SUCCESS);
	}

}
